//
//  NBAFeedBackViewController.m
//  NBAirCleaner
//
//  Created by 白浩洋 on 2018/2/8.
//  Copyright © 2018年 HaoYang. All rights reserved.
//

#import "NBAFeedBackViewController.h"
#import "PlaceholderTextView.h"
@interface NBAFeedBackViewController ()<UITextViewDelegate>
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic, strong) PlaceholderTextView * feedView;
@property (nonatomic,strong)UIButton *sendBtn;
@property (nonatomic,strong)UILabel *countLabel;
@end
@implementation NBAFeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addCustomTitleWithTitle:@"意见反馈"];
    [self addCustomBackBarButtonItemWithTarget:self action:@selector(backUp)];
    [self setUpUI];
}
- (void)setUpUI{
    self.feedView = [[PlaceholderTextView alloc]initWithFrame:CGRectMake(PXChange(40), PXChange(30), ScreenWidth - PXChange(80), PXChange(410))];
    self.feedView.delegate = self;
    self.feedView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    self.feedView.font = [UIFont systemFontOfSize:PXChange(28)];
    self.feedView.textColor = [UIColor blackColor];
    self.feedView.textAlignment = NSTextAlignmentLeft;
    self.feedView.editable = YES;
    self.feedView.placeholderColor = [UIColor colorWithHexString:@"#666666"];
    self.feedView.placeholder = @"请输入您的宝贵意见，我们会尽快处理!";
    [self.bgView addSubview:self.feedView];
    [self sendBtn];
}
- (UIButton *)sendBtn{
    if(!_sendBtn){
        _sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, PXChange(600), PXChange(100))];
        [_sendBtn.titleLabel setFont:[UIFont systemFontOfSize:PXChange(36)]];
        [_sendBtn setTitle:@"提交" forState:UIControlStateNormal];
        [_sendBtn setBackgroundColor:[UIColor colorWithHexString:@"#333333"]];
        _sendBtn.clipsToBounds = YES;
        _sendBtn.layer.cornerRadius = _sendBtn.height/2.0f;
        [_sendBtn addTarget:self action:@selector(sendClick:) forControlEvents:UIControlEventTouchUpInside];
        _sendBtn.backgroundColor = [UIColor colorWithHexString:BH_Color_Main];
         [self.sendBtn setTitleColor:[UIColor colorWithHexString:@"#ffffff"] forState:UIControlStateNormal];
        _sendBtn.center = CGPointMake(ScreenWidth/2.0f, ScreenHeight - 64 - _sendBtn.height/2.0f - PXChange(70) - iPhoneXTabHeigth);
        [self.bgView addSubview:_sendBtn];
    }
    return _sendBtn;
}
- (void)sendClick:(UIButton *)btn{
    [btn setEnabled:NO];
    [SVProgressHUD showInfoWithStatus:@"正在提交中。。。"];
    if(self.feedView.text.length > 0){
        BmobObject *gameScore = [BmobObject objectWithClassName:@"feedback"];
        [gameScore setObject:self.feedView.text forKey:@"feedValue"];
        [gameScore setObject:[BmobUser currentUser].username forKey:@"username"];
        [gameScore saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
            [SVProgressHUD dismiss];
             [btn setEnabled:YES];
            //进行操作
             [self backUp];
        }];
    }else{
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
        [SVProgressHUD showInfoWithStatus:@"输入内容为空哦！"];
        [SVProgressHUD dismissWithDelay:0.6];
    }
}
- (UIView *)bgView{
    if(!_bgView){
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, PXChange(20),ScreenWidth, ScreenHeight - PXChange(20) - 64)];
        _bgView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_bgView];
    }
    return _bgView;
}

@end
